/*
EvoGen, Evolutionary Geneura is a framework for simulating distributed evolutionary computation experiments
Copyright (C) 2008 Junta de Andalucia CICE project P06-TIC-02025

This file is part of EvoGen.

EvoGen is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

EvoGen is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with EvoGen; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

contact:  http://geneura.ugr.es, https://forja.rediris.es/svn/geneura/evogen
*/
package mirabilis.org.individuals.real;

import mirabilis.org.config.Configuration;
import mirabilis.org.individuals.IChromosome;
import mirabilis.org.individuals.Individual;


public class DoubleIndividual extends Individual {
	
	public double _euclidean;

	public DoubleIndividual(){
		_height = new double[Configuration.chromosome_size];
		_velocity = new double[Configuration.chromosome_size];
		for (int i=0;i<Configuration.chromosome_size;i++){
			_height[i]=0;
			_velocity[i]=0;
		}
		_distance2father = 0;
		_z1 = this;
		_z2 = this;
	}
	
	public DoubleIndividual(int length) {
		DoubleChromosome crm = new DoubleChromosome(length);
		setChr(crm);
		_height = new double[length];
		_velocity = new double[length];
		for (int i=0;i<chr.getLength();i++){
			_height[i]=0;
			_velocity[i]=0;
		}
		_distance2father = 0;
		_z1 = this;
		_z2 = this;
	}
	
	public DoubleIndividual(DoubleChromosome chromo) {
		DoubleChromosome crm = chromo;
		setChr(crm);
		_height = new double[chromo.getLength()];
		_velocity = new double[chromo.getLength()];
		for (int i=0;i<chr.getLength();i++){
			_height[i]=0;
			_velocity[i]=0;
		}
		_distance2father = 0;
		_z1 = this;
		_z2 = this;
	}
	
	
	
	public Object clone() {
		DoubleIndividual ind = new DoubleIndividual();
		ind.setChr((IChromosome)this.chr.clone());
		ind.fitness = this.fitness;
		ind.coop_fitness = this.coop_fitness;
		
		System.arraycopy(this._height,0, ind._height, 0,this._height.length);
		System.arraycopy(this._velocity,0, ind._velocity, 0,this._velocity.length);
		ind._distance2father = this._distance2father;
		ind._father = this._father;
		ind._z1 = this._z1;
		ind._z2 = this._z2;
		ind._euclidean = this._euclidean;		
		
		return ind;
	}

	public double distance(Individual ind) {
		
		
		double euclidean=0;
		for (int i=0;i<this.getChr().getLength();i++){
			euclidean += Math.pow(this.getChr().getGenAsDouble(i) - ind.getChr().getGenAsDouble(i),2);
		}
		
		euclidean = Math.sqrt(euclidean);
		
		return euclidean;
	}
}
